package jedis;

import com.alibaba.fastjson.JSON;
import entity.Goods;
import redis.clients.jedis.Jedis;

import java.util.Scanner;

public class jedisSearch {
    public static void main(String[] args) {
        System.out.println("输入要检索的商品编号");
        String goodsId = new Scanner(System.in).next();
        Jedis jedis = new Jedis("8.130.9.11", 6379);
        try {
            jedis.select(3);
            String key = "good:"+goodsId;
            if (jedis.exists(key)){
                String json = jedis.get(key);
                System.out.println(json);
                System.out.println("=========json转换为java对象============");
                Goods g = JSON.parseObject(json, Goods.class);
                System.out.println(g.toString());
            }else {
                System.out.println("不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            jedis.close();
        }

    }
}
